import {ActorState} from "db://assets/Script/Actor/ActorState";
import {StateEnum} from "db://assets/Script/Enums/StateEnum";
import {Vec2} from "cc";
import {AnimationEnum} from "db://assets/Script/Enums/AnimationEnum";


//待机状态
export class Idle extends ActorState {
    onEnter():void {
        console.log("执行该Idle状态逻辑,设置线性速度和动画状态")
        //设置刚体线性速度xy轴都为0
        this.actor.rigidBody2D.linearVelocity = new Vec2(0,0)
        //切换动画
        let hasIdle = this.animation.getState(AnimationEnum.PLAYER_IDLE);
        if (hasIdle) {
            console.log('待机状态动画存在')
            this.animation.play(AnimationEnum.PLAYER_IDLE)
            console.log('待机动画播放完毕')
        }
    }

    onDestroy():void {
    }

    onExit():void {
    }

    canTransition(to: StateEnum): boolean {
        //当前状态如果就是待机状态不能转待机状态 如果非待机状态可以转换其他状态
        let flag: boolean = to !== StateEnum.IDLE;
        console.log("Idle当前状态是否默认状态：", !flag, "状态为：", to)
        return flag
    }

    update(deltaTime: number) {
    }

}
